package com.ai.deepseekspring.config;

import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.redis.RedisVectorStore;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPooled;

@Configuration
public class VectorStoreConfig {

    @Bean
    public VectorStore vectorStore(EmbeddingModel embeddingModel,
                                   @Value("${spring.ai.vectorstore.redis.host:localhost}") String host,
                                   @Value("${spring.ai.vectorstore.redis.port:6379}") int port,
                                   @Value("${spring.ai.vectorstore.redis.index-name:custom-vector-index}") String indexName,
                                   @Value("${spring.ai.vectorstore.redis.prefix:custom-prefix}") String prefix,
                                   @Value("${spring.ai.vectorstore.redis.initialize-schema:true}") boolean initializeSchema) {

        JedisPooled jedis = new JedisPooled(host, port);

        return RedisVectorStore.builder(jedis, embeddingModel)
                .indexName(indexName)
                .prefix(prefix)
                .initializeSchema(initializeSchema)
                .build();
    }
}